﻿using Microsoft.Extensions.DependencyInjection;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DynamicQuartz.Core.SqlSugarExtension
{
    public static class SqlSugarExtensions
    {
        public static void AddSqlSugarClient(this IServiceCollection serviceCollection, List<Tuple<string, string, DbType>> tuples)
        {
            foreach (var item in tuples)
            {
                if (SqlSugarDataBase.DB(item.Item1) == null)
                {
                    var db = new Lazy<ISqlSugarClient>(() =>
                    {
                        SqlSugarClient sqlSugar = new SqlSugarClient(new ConnectionConfig()
                        {
                            DbType = item.Item3,
                            ConnectionString = item.Item2,
                            IsAutoCloseConnection = true,
                            // Oracle 多线程配置
                            MoreSettings = new ConnMoreSettings
                            {
                                IsAutoRemoveDataCache = true,
                                SqlServerCodeFirstNvarchar = true
                            }
                        },
                        db =>
                        {
                            db.Aop.OnLogExecuting = (sql, pars) =>
                            {

                            };
                        });
                        return sqlSugar;
                    });

                    SqlSugarDataBase.Add(item.Item1, db);
                }
            }


        }
    }
}
